#define _CRT_SECURE_NO_WARNINGS 1

#include "game.c"
void menu()
{
	printf("***********************\n");
	printf("******  1.play  *******\n");
	printf("******  0.exit  *******\n");
	printf("***********************\n");
}

void game()
{
	char ret = 0;
	//创建棋盘
	char board[ROW][COL] = { 0 };
	//初始化棋盘
	InitBoard(board, ROW, COL);
	//打印棋盘
	DisplayBoard(board, ROW, COL);

	while (1)
	{
		PlayerMove(board, ROW, COL);//玩家下棋
		system("cls");//清屏
		DisplayBoard(board, ROW, COL);//打印棋盘

		//判断输赢
		ret = IsWin(board, ROW, COL);
		if (ret != 'j')
		{
			break;
		}
	
		ComputerMove(board, ROW, COL);//电脑下棋
		delay(300000);
		system("cls");//清屏
		DisplayBoard(board, ROW, COL);//打印棋盘

		//判断输赢
		ret = IsWin(board, ROW, COL);
		if (ret != 'j')
		{
			break;
		}
	}

	if (ret == 'o') //玩家棋子为 o
	{
		delay(300000);
		printf("玩家赢\n");
	}
	else if (ret == 'x') //电脑棋子为 x
	{
		delay(300000);
		printf("电脑赢\n");
	}
	else
	{
		delay(300000);
		printf("平局\n");
	}
}

int main()
{
	int input = 0;
	srand((unsigned int)time(NULL));
	do
	{
		menu();
		printf("请选择：");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			system("cls");//清屏
			game();
			delay(500000);
			system("cls");//清屏
			break;
		case 0:
			printf("退出游戏！\n");
			break;
		default:
			printf("输入错误，请重新输入!!!\n");
			delay(500000);
			system("cls");//清屏
			break;
		}
	} while (input);

	return 0;
}